const userService = require("../services/userService");
const menuService = require("../services/menuService");
// 添加用户
exports.addUser = async (req, res) => {
  try {
    await userService.checkUser("add", req, res); // 校验用户名是否存在
    await userService.addUser(req, res); // 添加用户
  } catch (error) {
    res.tip(error);
  }
};
exports.getUserMenu = (req, res) => {
  const { id } = req.user;
  if (id === 1) {
    menuService.getMenuTreeList(req, res, "admin");
  } else {
    userService.getUserMenu(req, res);
  }
};

// 编辑用户
exports.editUser = async (req, res) => {
  try {
    await userService.checkUser("edit", req, res); // 校验用户名是否存在
    await userService.editUser(req, res);
  } catch (error) {
    res.tip(error);
  }
};
// 用户绑定菜单
exports.bindMenu = async (req, res) => {
  try {
    await userService.checkUserId(req);
    await userService.bindMenu(req, res);
  } catch (error) {
    res.tip(error);
  }
};
// 删除用户
exports.deleteUser = (req, res) => {
  userService.deleteUser(req, res);
};

// 获取用户列表
exports.getUserList = (req, res) => {
  userService.getUserPage(req, res);
};

// 获取用户select
exports.getUserSelect = (req, res) => {
  userService.getUserSelect(res);
};
// 获取用户绑定的menu_id数据(无子集数据)
exports.getBindMenuInfo = (req, res) => {
  userService.getBindMenuInfo(req, res);
};
